#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

typedef std::pair<float, float> PFF;

bool comparePoints(const PFF &a, const PFF &b, const PFF &center)
{
    double aAngle = atan2(a.second - center.second, a.first - center.first);
    double bAngle = atan2(b.second - center.second, b.first - center.first);
    return aAngle < bAngle;
}

void Sort_Points_Adapt_Polygon(std::vector<PFF> &points)
{
    // 获取中心点
    PFF center_point = std::make_pair(0, 0);
    for (int i = 0; i < points.size(); i++)
    {
        center_point.first += points[i].first;
        center_point.second += points[i].second;
    }
    center_point.first = center_point.first / points.size();
    center_point.second = center_point.second / points.size();
    std::cout << center_point.first << " " << center_point.second << std::endl;
    // 顺时针排序点集
    sort(points.begin(), points.end(), [center_point](const PFF &a, const PFF &b)
         { return comparePoints(a, b, center_point); });
};

int main()
{
    std::vector<PFF> points = {{100, 200}, {150, 50}, {300, 100}, {200, 250}};
    Sort_Points_Adapt_Polygon(points);
    for (auto item : points)
    {
        std::cout << item.first << " " << item.second << std::endl;
    }
    return 0;
}
